package com.crm.service.impl.opportunityManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customerManager.DemandAnalysisMapper;
import com.crm.dao.mapper.opportunityManager.OpportunityGiftMapper;
import com.crm.model.entity.customerManager.DemandAnalysis;
import com.crm.model.entity.customerManager.DemandAnalysisExample;
import com.crm.model.entity.opportunityManager.OpportunityGift;
import com.crm.model.entity.opportunityManager.OpportunityGiftExample;
import com.crm.service.opportunityManager.DemandAnalysisDbService;
import com.crm.service.opportunityManager.OpportunityGiftDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 需求分析
 */
@Service
public class DemandAnalysisDbServiceImpl implements DemandAnalysisDbService {

    @Autowired
    private DemandAnalysisMapper demandAnalysisMapper;

    /**
     * 商机-商机详情-需求分析
     * @param opportunityId 商机id
     * @param order  分组类型
     * @return
     */
    @Override
    public List<DemandAnalysis> demandAnalysisList(String opportunityId, String order) {
        DemandAnalysisExample demandAnalysisExample = new DemandAnalysisExample();
        DemandAnalysisExample.Criteria criteria = demandAnalysisExample.createCriteria();
        demandAnalysisExample.setOrderByClause(order);
        criteria.andOpportunityIdEqualTo(opportunityId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<DemandAnalysis> list = demandAnalysisMapper.selectByExample(demandAnalysisExample);
        return list;
    }

    /**
     * 商机管理-商机详情-新增需求分析
     * @param demandAnalysis 需求分析实体
     * @return
     */
    @Override
    public Boolean addDemandAnalysis(DemandAnalysis demandAnalysis) {
        Boolean result = false;
        int num = demandAnalysisMapper.insertSelective(demandAnalysis);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 商机-商机详情-修改需求分析
     * @param demandAnalysisId 需求分析id
     * @return
     */
    @Override
    public DemandAnalysis getDemandAnalysisById(String demandAnalysisId) {
        return demandAnalysisMapper.selectByPrimaryKey(demandAnalysisId);
    }

    /**
     * 商机详情-修改需求分析
     * @param demandAnalysis 需求分析实体
     * @return
     */
    @Override
    public Boolean updateDemandAnalysis(DemandAnalysis demandAnalysis) {
        Boolean result = false;
        int num = demandAnalysisMapper.updateByPrimaryKeySelective(demandAnalysis);
        if(num>0){
            result = true;
        }
        return result;
    }
}
